home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Server⁄PlayerPro 4.15 / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  6.2 KB  |  312 lines  |  [TEXT/KAHL]

  1. /* Main.c */
  2.  
  3. /* this file is based on "Simple Trecker.c" by Frank Seide */
  4.  
  5.  
  6. #include <sound.h>
  7. #include <GestaltEqu.h>
  8. #include <Power.h>
  9. #include "mac_event.h"
  10. #include "MAD.h"
  11. #include "RDriver.h"
  12.  
  13. #define CREATORCODE ('∫Tss')
  14. #define WAITNEXTEVENTDELAY (30)
  15.  
  16.  
  17. extern Boolean                                ReceivedOpenEventFlag;
  18. extern char                                        FakeKeyBuffer[MAXKEYS];
  19. extern int                                        KeyBufPtr;
  20.  
  21. extern Boolean                                QuitPending;
  22.  
  23. /* parameters controlling the synthesis, with handy default values. */
  24. extern short                                    AntiAliasing;
  25. extern short                                    StereoOn;
  26. extern unsigned short                    SamplingRate;
  27. extern short                                    NumRepeats;
  28. extern short                                    Speed;
  29. extern short                                    StereoMix;
  30. extern short                                    Loudness;
  31.  
  32. extern int                                        RecalibratePlayer; /* set when settings change */
  33.  
  34. extern FSSpec                                    GlobalFileSpec;
  35.  
  36.  
  37. long                                                    PowerManagerInfo = 0;
  38.  
  39. Boolean                                                Pausing = false;
  40.  
  41.  
  42. void                SetParameters(void);
  43.  
  44.  
  45. void                discard_buffer(void)
  46.     {
  47.     }
  48.  
  49.  
  50. void                HandleKeyBuffer(void)
  51.     {
  52.         WaitForEvent(15);
  53.      LoopPoint:
  54.         if (KeyBufPtr > 0)
  55.             {
  56.                 int                    Scan;
  57.                 int                    KeyTemp;
  58.  
  59.                 KeyTemp = (unsigned char)FakeKeyBuffer[0];
  60.                 for (Scan = 1; Scan < KeyBufPtr; Scan += 1)
  61.                     {
  62.                         FakeKeyBuffer[Scan - 1] = FakeKeyBuffer[Scan];
  63.                     }
  64.                 KeyBufPtr -= 1;
  65.                 switch (KeyTemp)
  66.                     {
  67.                         case '+':
  68.                 Loudness += 8;
  69.                 if (Loudness > 64)
  70.                   {
  71.                     Loudness = 64;
  72.                   }
  73.                             SetParameters();
  74.                             break;
  75.                         case '-':
  76.                 Loudness -= 8;
  77.                 if (Loudness < 0)
  78.                   {
  79.                     Loudness = 0;
  80.                   }
  81.                             SetParameters();
  82.                             break;
  83.                         case ' ':
  84.                             TogglePause();
  85.                             break;
  86.                         case '>':
  87.                             break;
  88.                         case '|':
  89.                             break;
  90.                         case '<':
  91.                             break;
  92.                     }
  93.                 goto LoopPoint;
  94.             }
  95.     }
  96.  
  97.  
  98. void            SetParameters(void)
  99.     {
  100.     }
  101.  
  102.  
  103. void            main(void)
  104.     {
  105.         short                    i;
  106.         short                    WorkingDirectoryRefNum;
  107.         OSErr                    Error;
  108.         long                    ProcTypeInfo;
  109.  
  110.         Boolean                Stereo;
  111.         Boolean                StereoMixing;
  112.         Boolean                NewSoundManager;
  113.         Boolean                hasASC;
  114.         long                    myBit;
  115.         long                    gestaltAnswer;
  116.         NumVersion        nVers;
  117.  
  118.  
  119.         /* this may not be necessary, but I'll do it anyway to avoid problems */
  120.         InitGraf (&thePort);
  121.         InitFonts();
  122.         FlushEvents (everyEvent, 0);
  123.         InitWindows();
  124.         InitMenus();
  125.         TEInit();
  126.         InitDialogs (NULL);
  127.          InitCursor();
  128.  
  129.         if (!RegisterEventHandlers())
  130.             {
  131.                 return;
  132.             }
  133.         Error = Gestalt(gestaltPowerMgrAttr,&PowerManagerInfo);
  134.         if (Error != noErr)
  135.             {
  136.                 return;
  137.             }
  138.         Error = Gestalt(gestaltProcessorType,&ProcTypeInfo);
  139.         if ((Error != noErr) || (ProcTypeInfo == gestalt68000))
  140.             {
  141.                 FatalError(FatalError68020NeededID);
  142.                 return;
  143.             }
  144.  
  145.         if ((PowerManagerInfo & (1 << gestaltPMgrExists)) != 0)
  146.             {
  147.                 DisableIdle();
  148.             }
  149.  
  150. #ifdef AskForFile
  151.         {
  152.             Point                                Thing = {50,50};
  153.             StandardFileReply        R;
  154.  
  155.             /* this is only used for debugging when we don't have access to the interface */
  156.             /* program (since the interface program can't link to this program when it */
  157.             /* is being run under the debugger.) */
  158.             StandardGetFile(NULL,-1,NULL,&R);
  159.             GlobalFileSpec = R.sfFile;
  160.         }
  161. #else
  162.         /* waiting for open document command to come */
  163.         while (!ReceivedOpenEventFlag && !QuitPending)
  164.             {
  165.                 WaitForEvent(60);
  166.             }
  167.         if (QuitPending)
  168.             {
  169.                 goto ExitPoint;
  170.             }
  171. #endif
  172.  
  173.         /* now loading the song.  First, coerce the FSSpec into a working directory */
  174.         OpenWD(GlobalFileSpec.vRefNum,GlobalFileSpec.parID,
  175.             CREATORCODE,&WorkingDirectoryRefNum);
  176.         SetVol((void*)0L/*novolname*/,WorkingDirectoryRefNum);
  177.         if (noErr != RLoadMOD(GlobalFileSpec.name))
  178.             {
  179.                 CloseWD(WorkingDirectoryRefNum);
  180.                 FatalError(FatalErrorInternalError);
  181.                 goto ExitPoint;
  182.             }
  183.         CloseWD(WorkingDirectoryRefNum);
  184.  
  185.         /* find out what driver we should use */
  186.         Gestalt(gestaltHardwareAttr,&gestaltAnswer);
  187.         myBit = gestaltHasASC;
  188.         if (!BitTst(&gestaltAnswer,31-myBit))
  189.             {
  190.                 hasASC = false;
  191.             }
  192.          else
  193.             {
  194.                 hasASC = true;
  195.             }
  196.         Gestalt(gestaltSoundAttr,&gestaltAnswer);
  197.         myBit = gestaltStereoCapability;
  198.         Stereo = BitTst(&gestaltAnswer,31-myBit);
  199.         myBit = gestaltStereoMixing;
  200.         StereoMixing = BitTst(&gestaltAnswer,31-myBit);
  201.         nVers = SndSoundManagerVersion();
  202.         if (nVers.majorRev >= 3)
  203.             {
  204.                 NewSoundManager = true;
  205.             }
  206.          else
  207.             {
  208.                 NewSoundManager = false;
  209.             }
  210.         /* initialize the library */
  211.         if (StereoOn && StereoMixing)
  212.             {
  213.                 if (NewSoundManager)
  214.                     {
  215.                         if (RInitMOD(SMStereo,thePartition.header->Tracks) != noErr)
  216.                             {
  217.                                 FatalError(FatalErrorInternalError);
  218.                                 goto ExitPoint;
  219.                             }
  220.                     }
  221.                 else if (hasASC)
  222.                     {
  223.                         if (RInitMOD(ASCStereo,thePartition.header->Tracks) != noErr)
  224.                             {
  225.                                 FatalError(FatalErrorInternalError);
  226.                                 goto ExitPoint;
  227.                             }
  228.                     }
  229.                 else
  230.                     {
  231.                         if (RInitMOD(SMDSP,thePartition.header->Tracks) != noErr)
  232.                             {
  233.                                 FatalError(FatalErrorInternalError);
  234.                                 goto ExitPoint;
  235.                             }
  236.                     }
  237.             }
  238.         else
  239.             {
  240.                 if (NewSoundManager)
  241.                     {
  242.                         if (RInitMOD(SMMono,thePartition.header->Tracks) != noErr)
  243.                             {
  244.                                 FatalError(FatalErrorInternalError);
  245.                                 goto ExitPoint;
  246.                             }
  247.                     }
  248.                 else if (hasASC)
  249.                     {
  250.                         if (RInitMOD(ASCMono,thePartition.header->Tracks) != noErr)
  251.                             {
  252.                                 FatalError(FatalErrorInternalError);
  253.                                 goto ExitPoint;
  254.                             }
  255.                     }
  256.                 else
  257.                     {
  258.                         FatalError(FatalErrorInternalError);
  259.                         goto ExitPoint;
  260.                     }
  261.             }
  262.  
  263.         /* begin playing the thing */
  264.         RPlayMOD();
  265.         Reading = true;
  266.  
  267.         /* now we do event loop waiting for codes & finish... */
  268.         while (!QuitPending)
  269.             {
  270.                 if (RecalibratePlayer)
  271.                     {
  272.                         SetParameters();
  273.                     }
  274.                 HandleKeyBuffer(); /* calls WaitForEvent */
  275.                 /* is the soundtrack done? */
  276.                 if (!Reading)
  277.                     {
  278.                         QuitPending = true;
  279.                     }
  280.             }
  281.  
  282.      PreExitPoint:
  283.         RStopMOD();  /* stop the music */
  284.         RClearMOD();  /* Clear MADF Music */
  285.         RQuitMOD();  /* Clear MADF Driver */
  286.  
  287.      ExitPoint:
  288.         if ((PowerManagerInfo & (1 << gestaltPMgrExists)) != 0)
  289.             {
  290.                 EnableIdle();
  291.             }
  292.     }
  293.  
  294.  
  295. void                TogglePause(void)
  296.     {
  297.         if (Pausing)
  298.             {
  299.                 Pausing = false;
  300.                 /* StartPChannel(pc); */
  301.             }
  302.          else
  303.             {
  304.                 Pausing = true;
  305.                 /* StopPChannel(pc,false); */
  306.                 while (Pausing && !QuitPending)
  307.                     {
  308.                         HandleKeyBuffer();
  309.                     }
  310.             }
  311.     }
  312.